//
//  LZRushCouponDetailTitleCell.m
//  LzzizDemo
//
//  Created by xbnzd on 16/11/7.
//  Copyright © 2016年 xbnzd. All rights reserved.
//

#import "LZFightGroupDetailTitleCell.h"
#import "GiftListLabel.h"

@interface LZFightGroupDetailTitleCell()
@property (weak, nonatomic) IBOutlet GiftListLabel *groupTitlelabel;
@property (weak, nonatomic) IBOutlet UIImageView *timeIcon;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *groupTitleBottomTimeLabelConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *groupTitleBottomSupeviewConstraint;



@end

@implementation LZFightGroupDetailTitleCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.groupTitlelabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
    self.groupTimeDownLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - self.timeIcon.intrinsicContentSize.width - 25;
    // Initialization code
}

- (void)loadTitle:(NSString *)title CouponState:(CouponState)couponState
{
    [self setRulesContentLabelText:title];
    if (couponState == kCoupon_used|| couponState == kCoupon_notUsed || couponState == kCoupon_expired) {
        _groupTitleBottomSupeviewConstraint.priority = 999;
        _groupTitleBottomTimeLabelConstraint.priority = 250;
        _groupTimeDownLabel.hidden = YES;
        _timeIcon.hidden = YES;
    }else{
        _groupTitleBottomSupeviewConstraint.priority = 250;
        _groupTitleBottomTimeLabelConstraint.priority = 999;
        _groupTimeDownLabel.hidden = NO;
        _timeIcon.hidden = NO;
    }
}

- (void)setRulesContentLabelText:(NSString *)text
{
    if (text.length <= 0) {
        return;
    }
    extern CGFloat textLineSpace;
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    
    [style setLineSpacing:textLineSpace];
    [style setLineBreakMode:NSLineBreakByWordWrapping];
    [style setAlignment:NSTextAlignmentLeft];
    
    [attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, attStr.length)];
    self.groupTitlelabel.attributedText = attStr;
}

#pragma mark -
#pragma mark action
- (void)configureLabel
{
    [self.groupTitlelabel setVerticalAlignment:VerticalAlignmentTop];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
